package com.itheima.tanhua.apiImpl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.tanhua.mapper.UserMapper;
import com.itheima.tanhua.pojo.db.User;
import com.itheima.tanhua.api.db.UserApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User getByPhone(String phone) {
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(User::getMobile,phone);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long uid) {
        return userMapper.selectById(uid);
    }

    @Override
    public User findByHuanxinId(String huaxinId) {

        LambdaQueryWrapper wrapper=new LambdaQueryWrapper();
        wrapper.eq("hxUser",huaxinId);
       return userMapper.selectOne(wrapper);
    }
}
